package com.yjc.drygoods.coupon.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yjc.drygoods.coupon.entity.CouponEntity;
import com.yjc.drygoods.coupon.service.CouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.List;

/**
 * @author yjc
 * @create 2022-10-18 14:39
 */
@Slf4j
@Controller
public class CouponWebController {

    @Autowired
    CouponService couponService;


    @GetMapping("/couponIndex.html")
    public String couponIndexPage(Model model) {
        //只显示已发布的和未失效的优惠券
        List<CouponEntity> list = couponService.list(new QueryWrapper<CouponEntity>().eq("publish", 1).gt("end_time", new Date()));
        model.addAttribute("couponInfo", list);
        return "couponIndex";
    }
}
